<!DOCTYPE html>
<html  lang="zh">
<head>
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="utf-8" />

<meta name="generator" content="Hexo 3.9.0" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

<title>shader学习1-顶点/片元着色器的基本结构 - 游戏人生</title>


    <meta name="description" content="shade学习">
<meta name="keywords" content="学习">
<meta property="og:type" content="article">
<meta property="og:title" content="shader学习1-顶点&#x2F;片元着色器的基本结构">
<meta property="og:url" content="http://cloundgame.gitee.io/mystudy/2019/08/19/shade学习-1/index.html">
<meta property="og:site_name" content="游戏人生">
<meta property="og:description" content="shade学习">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">
<meta property="og:updated_time" content="2020-07-15T05:28:57.227Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="shader学习1-顶点&#x2F;片元着色器的基本结构">
<meta name="twitter:description" content="shade学习">
<meta name="twitter:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">







<link rel="icon" href="/mystudy/images/favicon.svg">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.9.0/css/all.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-dark.css">


    
    
    
    <style>body>.footer,body>.navbar,body>.section{opacity:0}</style>
    

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">
    

    
    

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">


    
    
    
    

<link rel="stylesheet" href="/mystudy/css/back-to-top.css">


    
    

    
    
    
    

    
    
<link rel="stylesheet" href="/mystudy/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

    
    
    
        <script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    

    


<link rel="stylesheet" href="/mystudy/css/style.css"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>
<body class="is-3-column">
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/mystudy/">
            
                <img src="/mystudy/images/logo.svg" alt="shader学习1-顶点/片元着色器的基本结构" height="28">
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/mystudy/">主页</a>
                
                <a class="navbar-item"
                href="/mystudy/archives">日志</a>
                
                <a class="navbar-item"
                href="/mystudy/categories">分类</a>
                
                <a class="navbar-item"
                href="/mystudy/">关于</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    
                    <a class="navbar-item" target="_blank" title="Download on GitHub" href="https://github.com/koliy/koliy.github.io">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                <a class="navbar-item is-hidden-tablet catalogue" title="目录" href="javascript:;">
                    <i class="fas fa-list-ul"></i>
                </a>
                
                
                <a class="navbar-item search" title="搜索" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-6-widescreen has-order-2 column-main"><div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2019-08-19T08:52:50.000Z">2019-08-19</time>
                
                <div class="level-item">
                <a class="has-link-grey -link" href="/mystudy/categories/shade学习/">shade学习</a>
                </div>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    18 分钟 读完 (大约 2737 个字)
                </span>
                
                
                <span class="level-item has-text-grey" id="busuanzi_container_page_pv">
                    <i class="far fa-eye"></i>
                    <span id="busuanzi_value_page_pv">0</span>次访问
                </span>
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                shader学习1-顶点/片元着色器的基本结构
            
        </h1>
        <div class="content">
            <h2 id="顶点-片元着色器的基本结构"><a href="#顶点-片元着色器的基本结构" class="headerlink" title="顶点/片元着色器的基本结构"></a><strong>顶点/片元着色器的基本结构</strong></h2><a id="more"></a>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="hljs-string">"MyShaderName"</span>&#123;</span><br><span class="line">	Properties&#123;</span><br><span class="line">		<span class="hljs-comment">//属性</span></span><br><span class="line">	&#125;</span><br><span class="line">	SubShader&#123;</span><br><span class="line">		<span class="hljs-comment">//针对显卡A的SubShader</span></span><br><span class="line">		Pass&#123;</span><br><span class="line">			<span class="hljs-comment">//设置渲染状态和标签</span></span><br><span class="line">			</span><br><span class="line">			<span class="hljs-comment">//开始CG代码片段</span></span><br><span class="line">			CGPROGRAM</span><br><span class="line">			<span class="hljs-comment">//该代码片段的编译指令</span></span><br><span class="line">			#pragma vertex vert</span><br><span class="line">			#pragma fragment frag</span><br><span class="line">			</span><br><span class="line">			<span class="hljs-comment">//CG 代码写这里</span></span><br><span class="line">			</span><br><span class="line">			ENDCG</span><br><span class="line">			</span><br><span class="line">			<span class="hljs-comment">//其它设置</span></span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="hljs-comment">//其它需要的Pass</span></span><br><span class="line">		Pass&#123;&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	SubShader&#123;</span><br><span class="line">		<span class="hljs-comment">//针对显卡B的Subshader</span></span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="hljs-comment">//上述SubShader都失败后用于回调Unity的Shader</span></span><br><span class="line">	Fallback <span class="hljs-string">"VertexLit"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="0-状态和标签"><a href="#0-状态和标签" class="headerlink" title="0 状态和标签"></a><strong>0 状态和标签</strong></h4><p><strong>SubShader中定义了一系列Pass以及可选的状态和标签设置。如果我们在SubShader进行了这些设置，那么将会用于所有Pass，如果只想对单个Pass有效，则可在Pass里面定义状态和标签设置</strong></p>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">SubShader&#123;</span><br><span class="line">	<span class="hljs-comment">//标签，可选</span></span><br><span class="line">	[Tags]</span><br><span class="line">	<span class="hljs-comment">//状态，可选</span></span><br><span class="line">	[RenderSetup]</span><br><span class="line">	</span><br><span class="line">	Pass&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="0-1-状态设置"><a href="#0-1-状态设置" class="headerlink" title="0.1 状态设置"></a><strong>0.1 状态设置</strong></h6><table>
<thead>
<tr>
<th>状态名称</th>
<th>设置指令</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>Cull</td>
<td>Cull Back\Front\Off</td>
<td>设置剔除模式：剔除背面\正面\关闭剔除</td>
</tr>
<tr>
<td>ZTest</td>
<td>ZTest Less Greater\LEqual\GEqual\Equal\NotEqual\Always</td>
<td>设置深度测试时使用的函数:大于\小于\不等于</td>
</tr>
<tr>
<td>Zwrite</td>
<td>ZWrite On\Off</td>
<td>开启\关闭深度写入</td>
</tr>
<tr>
<td>Blend</td>
<td>Blend SrcFactor DstFactor</td>
<td>开启并设置混合模式</td>
</tr>
</tbody></table>
<h6 id="0-2-标签设置"><a href="#0-2-标签设置" class="headerlink" title="0.2 标签设置"></a><strong>0.2 标签设置</strong></h6><p><strong>SubShader的标签是一个键值对，它的键和值都是字符串类型，它们用来告诉Unity的渲染引擎，subshader希望怎样以及何时渲染这个对象</strong></p>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Tags&#123;<span class="hljs-string">"TagName1"</span>=<span class="hljs-string">"Value1"</span> <span class="hljs-string">"TagName2"</span>=<span class="hljs-string">"Value2"</span>&#125;</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>标签类型</th>
<th>说明</th>
<th>例子</th>
</tr>
</thead>
<tbody><tr>
<td>Queue</td>
<td>控制渲染顺序，指定物体属于哪一个渲染队列，可控制透明物体在所有不透明物体后面被渲染</td>
<td>Tags{“Queue”=”Transparent”}</td>
</tr>
<tr>
<td>RenderType</td>
<td>对着色器进行分类，例如这是一个不透明\透明的着色器</td>
<td>Tags{“RenderType”=”Opaque”}</td>
</tr>
<tr>
<td>DisableBatching</td>
<td>通过该标签指明是否对该subshader使用批处理</td>
<td>Tags{“DisableBatching”=”True”}</td>
</tr>
<tr>
<td>ForceNoShadowCasting</td>
<td>控制使用该subshader的物体是否会投射阴影</td>
<td>Tags{“ForceNoShadowCasting”=”True”}</td>
</tr>
<tr>
<td>IgnoreProjector</td>
<td>忽略周围阴影影响，通常用于半透明物体</td>
<td>Tags{“IgnoreProjector”=”True”}</td>
</tr>
<tr>
<td>CanUseSpriteAtlas</td>
<td>当该subshader用于sprite时，设置false</td>
<td>Tags{“CanUseSpriteAtlas”=”false”}</td>
</tr>
<tr>
<td>PreviewType</td>
<td>指明材质面板如何预览该材质</td>
<td>Tags{“PreviewType”=”Plane”}</td>
</tr>
</tbody></table>
<p><strong>上述标签只可在SubShader中定义设置，不可在Pass里面，Pass另有自己的标签定义</strong></p>
<h6 id="0-3-Pass标签设置"><a href="#0-3-Pass标签设置" class="headerlink" title="0.3 Pass标签设置"></a><strong>0.3 Pass标签设置</strong></h6><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Pass&#123;</span><br><span class="line">	<span class="hljs-comment">//Pass名，用于其它shader引用</span></span><br><span class="line">	[Name]</span><br><span class="line">	<span class="hljs-comment">//标签，可选</span></span><br><span class="line">	[Tags]</span><br><span class="line">	<span class="hljs-comment">//状态，可选</span></span><br><span class="line">	[RenderSetup]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Name <span class="hljs-string">"MyPassName"</span></span><br><span class="line">ShaderLab可使用UsePass命令来直接使用其他Shadr的Pass,提高复用性。</span><br><span class="line">UsePass <span class="hljs-string">"MyShader/MYPASSNAME"</span></span><br><span class="line">由于Unity内部会把所有Pass的名称转换成大写字母的表示，因此UsePass命令必须要使用大写形式的名称</span><br></pre></td></tr></table></figure>

<p><strong>Pass的标签类型</strong></p>
<table>
<thead>
<tr>
<th>标签类型</th>
<th>说明</th>
<th>例子</th>
</tr>
</thead>
<tbody><tr>
<td>LightMode</td>
<td>定义该Pass在Unity的光照流水线中的角色,才能使用Unity的内置光照变量</td>
<td>Tags{“LightMode”=”ForwardBase”}</td>
</tr>
<tr>
<td>RequireOptions</td>
<td>用于指定当满足某些条件时才渲染该Pass</td>
<td>Tags{“RequireOptions”=”SoftVegetation”}</td>
</tr>
</tbody></table>
<h4 id="1-编译指令"><a href="#1-编译指令" class="headerlink" title="1 编译指令"></a><strong>1 编译指令</strong></h4><p><strong>它们将告诉Unity，哪个函数包含顶点着色器的代码，哪个函数包含片元着色器的代码</strong></p>
<figure class="highlight hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#pragma vertex vert  //顶点着色器函数 vert</span><br><span class="line">#pragma fragment frag //片元着色器函数frag</span><br></pre></td></tr></table></figure>

<h6 id="1-1-顶点着色器函数"><a href="#1-1-顶点着色器函数" class="headerlink" title="1.1 顶点着色器函数"></a><strong>1.1 顶点着色器函数</strong></h6><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">float4 vert(float4 v: POSITION):SV_POSITION&#123;</span><br><span class="line">	<span class="hljs-keyword">return</span> mul(UNITY_MATRIX_MVP, v);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>它是逐顶点执行的,vert函数的输入V包含了这个顶点的位置</strong></p>
<h6 id="1-2-片元着色器函数"><a href="#1-2-片元着色器函数" class="headerlink" title="1.2 片元着色器函数"></a><strong>1.2 片元着色器函数</strong></h6><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">float4 frag(v2f i):SV_Target&#123;</span><br><span class="line">	<span class="hljs-keyword">return</span> fixed4(<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>它是逐片元调用的，片元着色器中的输入实际上是 把顶点着色器的输出进行插值后得到的结果。片元着色器输出的颜色的每个分量范围在[0,1]</strong></p>
<h6 id="1-3-数据结构"><a href="#1-3-数据结构" class="headerlink" title="1.3 数据结构"></a><strong>1.3 数据结构</strong></h6><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">struct a2v&#123;</span><br><span class="line">	<span class="hljs-comment">//POSITION语义告诉Unity，用模型空间的顶点坐标填充vertex变量</span></span><br><span class="line">	float4 vertex: POSITION;</span><br><span class="line">	<span class="hljs-comment">//NORMAL语义告诉Unity, 用模型空间的法线方向填充normal变量</span></span><br><span class="line">	float3 normal: NORMAL;</span><br><span class="line">	<span class="hljs-comment">//TEXCOORD0语义告诉Unity, 用模型的第一套纹理坐标填充texcoord变量</span></span><br><span class="line">	float4 texcoord: TEXCOORD0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="1-4-语义"><a href="#1-4-语义" class="headerlink" title="1.4 语义"></a><strong>1.4 语义</strong></h6><figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">POSITION: </span><br><span class="line">	将告诉Unity,把模型的顶点坐标填充到输入参数v中，类型是float4</span><br><span class="line">NORMAL:</span><br><span class="line">	告诉Unity,用模型空间的法线方向填充normal变量,类型是float3</span><br><span class="line">TANGENT:</span><br><span class="line">	告诉Unity,用模型空间的切线方向填充tagent变量,类型是float3</span><br><span class="line">TEXCOORD0~n:</span><br><span class="line">	告诉Unity,用模型的第一套纹理坐标填充texcoord变量,类型是float2,float4</span><br><span class="line">SV_POSITION: </span><br><span class="line">	将告诉Unity，顶点着色器的输出是裁剪空间中的顶点坐标，用于光栅化，类型是float4</span><br><span class="line">SV_Target:</span><br><span class="line">	将告诉Unity渲染器，把用户的输出颜色存储到一个渲染目标中，默认输出到帧缓存中，类型是fixed4</span><br><span class="line">COLOR:</span><br><span class="line">	用于存储顶点颜色信息，类型是fixed4，float4</span><br></pre></td></tr></table></figure>

<p><strong>数据是由该材质的MeshRender组件提供，在每帧调用DrawCall时，MeshRender组件会把它负责的模型数据发送给shader</strong><br><strong>我们知道，一个模型包含一组三角面片，每个三角面片由3个顶点构成，而每个顶点又包含一些数据，如顶点位置，法线，切线，顶点颜色，纹理坐标等，通过语义我们就可以在顶点着色器中访问顶点的这些模型数据</strong></p>
<h6 id="1-5-顶点着色器和片元着色器通信"><a href="#1-5-顶点着色器和片元着色器通信" class="headerlink" title="1.5 顶点着色器和片元着色器通信"></a><strong>1.5 顶点着色器和片元着色器通信</strong></h6><p><strong>我们往往希望从顶点着色器输出一些数据，如模型的法线，纹理坐标给片元着色器，这就需要2者间通信</strong><br><strong>片元着色器中的输入实际上是 把顶点着色器的输出进行插值后得到的结果</strong></p>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">struct a2v&#123;</span><br><span class="line">	<span class="hljs-comment">//POSITION语义告诉Unity，用模型空间的顶点坐标填充vertex变量</span></span><br><span class="line">	float4 vertex: POSITION;</span><br><span class="line">	<span class="hljs-comment">//NORMAL语义告诉Unity, 用模型空间的法线方向填充normal变量</span></span><br><span class="line">	float3 normal: NORMAL;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">struct v2f&#123;</span><br><span class="line">	<span class="hljs-comment">//SV_POSITION语义告诉unity,pos包含顶点在裁剪空间中的坐标信息</span></span><br><span class="line">	float4 pos: SV_POSTION;</span><br><span class="line">	<span class="hljs-comment">//color变量用于存储颜色信息</span></span><br><span class="line">	fixed3 color: COLOR0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">v2f vert(a2v v):SV_POSITION&#123;</span><br><span class="line">	v2f o;</span><br><span class="line">	o.pos = mul(UNITY_MATRIX_MVP, v.vertex);</span><br><span class="line">	o.color = v.normal * <span class="hljs-number">0.5</span>+fixed3(<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>);</span><br><span class="line">	<span class="hljs-keyword">return</span> o;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">fixed4 frag(v2f i):SV_Target&#123;</span><br><span class="line">	<span class="hljs-comment">//将插值后的i.color显示在屏幕上</span></span><br><span class="line">	<span class="hljs-keyword">return</span> fixed4(i.color,<span class="hljs-number">1.0</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-属性"><a href="#2-属性" class="headerlink" title="2 属性"></a><strong>2 属性</strong></h4><table>
<thead>
<tr>
<th>Properties属性类型</th>
<th>CG变量类型</th>
<th>例子</th>
</tr>
</thead>
<tbody><tr>
<td>Int</td>
<td>float,half,fixed</td>
<td>_Int(“Int”,Int) =2</td>
</tr>
<tr>
<td>Float</td>
<td>float,half,fixed</td>
<td>_Float(“Float”,Float)=1.5</td>
</tr>
<tr>
<td>Range</td>
<td>float,half,fixed</td>
<td>_Range(“Range”,Range(0,5.0))=3.0</td>
</tr>
<tr>
<td>Color,Vector</td>
<td>float4,half4,fixed4</td>
<td>_Color(“Color”,Color)=(1,1,1,1)</td>
</tr>
<tr>
<td>2D</td>
<td>sampler2D</td>
<td>_2D(“2D”,2D)=””{}</td>
</tr>
<tr>
<td>3D</td>
<td>sampler3D</td>
<td>_3D(“3D”,3D)=”black”{}</td>
</tr>
<tr>
<td>Cube</td>
<td>samplerCube</td>
<td>_Cube(“Cube”,Cube)=”white”{}</td>
</tr>
</tbody></table>
<p><strong>float: 4字节大小<br>half: 2字节大小，取值范围 -60000..+60000<br>fixed: 2字节大小，取值范围 -2.0..+2.0<br>float4，half4,fixed4:表示为四元数=｛1.0,1.0,1.0,1.0｝</strong></p>
<p><strong>2D,3D,Cube 纹理格式：</strong><br><strong>_3D(“_3D”,_3D)=”black”{}</strong><br><strong>black为内置纹理名称，如”white,black,gray,bump,可为空，{}用处原本是用于指定一些纹理属性，unity5.0放弃，保持默认</strong></p>
<p><strong>格式：</strong><br>propertiesname (“mertial上显示的名称”, Properties属性类型) =(属性值)</p>
<p>如：</p>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Properties&#123;</span><br><span class="line">	<span class="hljs-comment">//声明一个Color类型的属性</span></span><br><span class="line">	_Color (<span class="hljs-string">"Color init"</span>,Color)=(<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>,<span class="hljs-number">1.0</span>)</span><br><span class="line">&#125;</span><br><span class="line">Pass&#123;</span><br><span class="line">	CGPROGRAM</span><br><span class="line">	<span class="hljs-comment">//在CG代码中，需要定义个与属性名称和类型都匹配的变量，fixed4的CG类型，变量都是_Color</span></span><br><span class="line">	fixed4 _Color;</span><br><span class="line">	ENDCG</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="3-内置文件"><a href="#3-内置文件" class="headerlink" title="3 内置文件"></a><strong>3 内置文件</strong></h4><table>
<thead>
<tr>
<th>文件名</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>UnityCG.cginc</td>
<td>包含最常用的帮助函数，宏和结构体等</td>
</tr>
<tr>
<td>UnityShaderVariables.cginc</td>
<td>在编译shader时，自动包含进来，包含了许多内置的全局变量，如UNITY_MATRIX_MVP等</td>
</tr>
<tr>
<td>Lighting.cginc</td>
<td>包含了各种内置的光照模型，如果编写的上surface shader,则自动包含进来</td>
</tr>
<tr>
<td>HLSLSupport.cginc</td>
<td>编译shader时，自动包含进来，声明了很多用于跨平台编译的宏和定义</td>
</tr>
</tbody></table>
<figure class="highlight javascript hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">CGPROGRAM</span><br><span class="line"></span><br><span class="line">#include "UnityCG.cginc"</span><br><span class="line"></span><br><span class="line">ENDCG</span><br></pre></td></tr></table></figure>

<h6 id="3-1-UnityCG-cginc中一些常用的结构体"><a href="#3-1-UnityCG-cginc中一些常用的结构体" class="headerlink" title="3.1 UnityCG.cginc中一些常用的结构体"></a><strong>3.1 UnityCG.cginc中一些常用的结构体</strong></h6><table>
<thead>
<tr>
<th>文件名</th>
<th>描述</th>
<th>包含变量</th>
</tr>
</thead>
<tbody><tr>
<td>appdata_base</td>
<td>用于顶点着色器的输入</td>
<td>顶点位置，法线，第一组纹理坐标</td>
</tr>
<tr>
<td>appdata_tan</td>
<td>用于顶点着色器的输入</td>
<td>顶点位置，法线，切线，第一组纹理坐标</td>
</tr>
<tr>
<td>appdata_full</td>
<td>用于顶点着色器的输入</td>
<td>顶点位置，法线，切线,四组/更多纹理坐标</td>
</tr>
<tr>
<td>appdata_img</td>
<td>用于顶点着色器的输入</td>
<td>顶点位置，第一组纹理坐标</td>
</tr>
<tr>
<td>v2f_img</td>
<td>用于顶点着色器的输出</td>
<td>裁剪空间中的位置，纹理坐标</td>
</tr>
</tbody></table>
<h6 id="3-2-UnityCG-cginc中一些常用的帮助函数"><a href="#3-2-UnityCG-cginc中一些常用的帮助函数" class="headerlink" title="3.2 UnityCG.cginc中一些常用的帮助函数"></a><strong>3.2 UnityCG.cginc中一些常用的帮助函数</strong></h6><table>
<thead>
<tr>
<th>函数名</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>float3 WorldSpaceViewDir(float4 v)</td>
<td>输入一个模型空间中的顶点位置，返回世界空间中从该点到摄像机的观察方向</td>
</tr>
<tr>
<td>float3 ObjSpaceViewDir(float4 v)</td>
<td>输入一个模型空间中的顶点位置，返回模型空间中从该点到摄像机的观察方向</td>
</tr>
<tr>
<td>float3 UnityObjectToViewDir(float4 v)</td>
<td>输入一个模型空间中的顶点位置，返回模型空间中从该点到摄像机的观察方向</td>
</tr>
<tr>
<td>float3 UnityWorldSpaceViewDir(float4 v)</td>
<td>输入一个世界空间中的顶点位置，返回世界空间中从该点到摄像机的观察方向</td>
</tr>
<tr>
<td>float3 WorldSpaceLightDir(float4 v)</td>
<td>仅用于前向渲染中。输入一个模型空间中的顶点位置，返回世界空间中从该点到光源的光照方向，没有被归一化</td>
</tr>
<tr>
<td>float3 ObjSpaceLightDir(float4 v)</td>
<td>仅用于前向渲染中。输入一个模型空间中的顶点位置，返回模型空间中从该点到光源的光照方向，没有被归一化</td>
</tr>
<tr>
<td>float3 UnityWorldSpaceLightDir(float4 v)</td>
<td>仅用于前向渲染中。输入一个世界空间中的顶点位置，返回世界空间中从该点到光源的光照方向，没有被归一化</td>
</tr>
<tr>
<td>float3 UnityObjectToWorldNormal(float3 n)</td>
<td>把法线方向从模型空间转换到世界空间</td>
</tr>
<tr>
<td>float3 UnityObjectToWorldDir(in float3 dir)</td>
<td>把方向矢量从模型空间转换到世界空间</td>
</tr>
<tr>
<td>float3 UnityWorldToObjectDir(float3 dir)</td>
<td>把方向矢量从世界空间转换到模型空间</td>
</tr>
<tr>
<td>float4 UnityObjectToClipPos(float4 v)</td>
<td>输入模型空间的顶点位置，返回裁剪空间中的位置</td>
</tr>
<tr>
<td>float4 mul(_Object2World,v.vertex)</td>
<td>输入模型空间的顶点位置，返回世界空间中的位置</td>
</tr>
<tr>
<td>float4 mul(UNITY_MATRIX_MV,v.vertex)</td>
<td>输入模型空间的顶点位置，返回观察空间中的位置</td>
</tr>
<tr>
<td>float4 mul((float3x3)UNITY_MATRIX_IT_MV,v.normal)</td>
<td>输入模型空间的法线，返回观察空间中的位置</td>
</tr>
</tbody></table>
<h4 id="4-Shader-Model"><a href="#4-Shader-Model" class="headerlink" title="4 Shader Model"></a><strong>4 Shader Model</strong></h4><p><strong>是由微软提出的一套规范，通俗理解就是它们决定了shader中各个特性的能力，这些特性和能力体现了shader能使用的运算指令数目，寄存器个数等，等级越高，能力越大</strong></p>
<h6 id="4-1-Unity支持的Shader-Target"><a href="#4-1-Unity支持的Shader-Target" class="headerlink" title="4.1 Unity支持的Shader Target"></a><strong>4.1 Unity支持的Shader Target</strong></h6><table>
<thead>
<tr>
<th>指令</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>#pragma target 2.0</td>
<td>默认的shader target等级，相当于DX9上的shader model2.0</td>
</tr>
<tr>
<td>#pragma target 3.0</td>
<td>相当于DX9上的shader model3.0</td>
</tr>
<tr>
<td>#pragma target 4.0</td>
<td>相当于DX10上的shader model4.0 ，目前只在DX11，Xbox/ps4平台提供</td>
</tr>
<tr>
<td>#pragma target 5.0</td>
<td>相当于DX11上的shader model5.0，目前只在DX11，Xbox/ps4平台提供</td>
</tr>
</tbody></table>

        </div>
        
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <span class="is-size-6 has-text-grey has-mr-7">#</span>
                    <a class="has-link-grey -link" href="/mystudy/tags/学习/">学习</a>
                </div>
            </div>
        </div>
        
        

        
        <div class="social-share"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css">
<script src="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/js/social-share.min.js"></script>
        
    </div>
</div>





<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/mystudy/2019/08/22/xlua学习/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">xlua学习</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/mystudy/2019/08/19/study-game-image-1/">
                <span class="level-item">3D数学基础:图形与游戏开发-向量</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>


</div>
                




<div class="column is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
    
        
<div class="card widget">
    <div class="card-content">
        <nav class="level">
            <div class="level-item has-text-centered" style="flex-shrink: 1">
                <div>
                    
                        <img class="image is-128x128 has-mb-6" src="/mystudy/images/avatar2.jpg" alt="满头大汉老黄牛">
                    
                    
                    <p class="is-size-4 is-block">
                        满头大汉老黄牛
                    </p>
                    
                    
                    <p class="is-size-6 is-block">
                        游戏
                    </p>
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>火星</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level is-mobile">
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        文章
                    </p>
                    <p class="title has-text-weight-normal">
                        70
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        分类
                    </p>
                    <p class="title has-text-weight-normal">
                        10
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        标签
                    </p>
                    <p class="title has-text-weight-normal">
                        3
                    </p>
                </div>
            </div>
        </nav>
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://github.com/koliy/" target="_blank">
                关注我</a>
        </div>
        
        
        <div class="level is-mobile">
            
            <a class="level-item button is-white is-marginless" target="_blank"
                title="Github" href="https://github.com/koliy/">
                
                <i class="fab fa-github"></i>
                
            </a>
            
        </div>
        
    </div>
</div>
    
        


    
        
<div class="card widget">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                分类
            </h3>
            <ul class="menu-list">
            <li>
        <a class="level is-marginless" href="/mystudy/categories/3D数学基础-图形与游戏开发/">
            <span class="level-start">
                <span class="level-item">3D数学基础:图形与游戏开发</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/AI/">
            <span class="level-start">
                <span class="level-item">AI</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">12</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/MySql/">
            <span class="level-start">
                <span class="level-item">MySql</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/SurfaceShader/">
            <span class="level-start">
                <span class="level-item">SurfaceShader</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/Unity/">
            <span class="level-start">
                <span class="level-item">Unity</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/git/">
            <span class="level-start">
                <span class="level-item">git</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/shade学习/">
            <span class="level-start">
                <span class="level-item">shade学习</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">33</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/xlua/">
            <span class="level-start">
                <span class="level-item">xlua</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/网络同步/">
            <span class="level-start">
                <span class="level-item">网络同步</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">10</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/设计模式/">
            <span class="level-start">
                <span class="level-item">设计模式</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">5</span>
            </span>
        </a></li>
            </ul>
        </div>
    </div>
</div>
    
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/09/">
                <span class="level-start">
                    <span class="level-item">九月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/07/">
                <span class="level-start">
                    <span class="level-item">七月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">23</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/06/">
                <span class="level-start">
                    <span class="level-item">六月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">17</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">三月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/02/">
                <span class="level-start">
                    <span class="level-item">二月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">4</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/09/">
                <span class="level-start">
                    <span class="level-item">九月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">5</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/08/">
                <span class="level-start">
                    <span class="level-item">八月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">18</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
    
        
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            标签云
        </h3>
        <a href="/mystudy/tags/game/" style="font-size: 15px;">game</a> <a href="/mystudy/tags/git/" style="font-size: 10px;">git</a> <a href="/mystudy/tags/学习/" style="font-size: 20px;">学习</a>
    </div>
</div>

    
    
        <div class="column-right-shadow is-hidden-widescreen is-sticky">
        
            
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#顶点-片元着色器的基本结构">
        <span class="has-mr-6">1</span>
        <span>顶点/片元着色器的基本结构</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#0-状态和标签">
        <span class="has-mr-6">1.1</span>
        <span>0 状态和标签</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#0-1-状态设置">
        <span class="has-mr-6">1.1.1</span>
        <span>0.1 状态设置</span>
        </a></li><li>
        <a class="is-flex" href="#0-2-标签设置">
        <span class="has-mr-6">1.1.2</span>
        <span>0.2 标签设置</span>
        </a></li><li>
        <a class="is-flex" href="#0-3-Pass标签设置">
        <span class="has-mr-6">1.1.3</span>
        <span>0.3 Pass标签设置</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#1-编译指令">
        <span class="has-mr-6">1.2</span>
        <span>1 编译指令</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-1-顶点着色器函数">
        <span class="has-mr-6">1.2.1</span>
        <span>1.1 顶点着色器函数</span>
        </a></li><li>
        <a class="is-flex" href="#1-2-片元着色器函数">
        <span class="has-mr-6">1.2.2</span>
        <span>1.2 片元着色器函数</span>
        </a></li><li>
        <a class="is-flex" href="#1-3-数据结构">
        <span class="has-mr-6">1.2.3</span>
        <span>1.3 数据结构</span>
        </a></li><li>
        <a class="is-flex" href="#1-4-语义">
        <span class="has-mr-6">1.2.4</span>
        <span>1.4 语义</span>
        </a></li><li>
        <a class="is-flex" href="#1-5-顶点着色器和片元着色器通信">
        <span class="has-mr-6">1.2.5</span>
        <span>1.5 顶点着色器和片元着色器通信</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#2-属性">
        <span class="has-mr-6">1.3</span>
        <span>2 属性</span>
        </a></li><li>
        <a class="is-flex" href="#3-内置文件">
        <span class="has-mr-6">1.4</span>
        <span>3 内置文件</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#3-1-UnityCG-cginc中一些常用的结构体">
        <span class="has-mr-6">1.4.1</span>
        <span>3.1 UnityCG.cginc中一些常用的结构体</span>
        </a></li><li>
        <a class="is-flex" href="#3-2-UnityCG-cginc中一些常用的帮助函数">
        <span class="has-mr-6">1.4.2</span>
        <span>3.2 UnityCG.cginc中一些常用的帮助函数</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#4-Shader-Model">
        <span class="has-mr-6">1.5</span>
        <span>4 Shader Model</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#4-1-Unity支持的Shader-Target">
        <span class="has-mr-6">1.5.1</span>
        <span>4.1 Unity支持的Shader Target</span>
        </a></li></ul></li></ul></li></ul>
        </div>
    </div>
</div>

        
        </div>
    
</div>

                




<div class="column is-4-tablet is-4-desktop is-3-widescreen is-hidden-touch is-hidden-desktop-only has-order-3 column-right is-sticky">
    
        
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#顶点-片元着色器的基本结构">
        <span class="has-mr-6">1</span>
        <span>顶点/片元着色器的基本结构</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#0-状态和标签">
        <span class="has-mr-6">1.1</span>
        <span>0 状态和标签</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#0-1-状态设置">
        <span class="has-mr-6">1.1.1</span>
        <span>0.1 状态设置</span>
        </a></li><li>
        <a class="is-flex" href="#0-2-标签设置">
        <span class="has-mr-6">1.1.2</span>
        <span>0.2 标签设置</span>
        </a></li><li>
        <a class="is-flex" href="#0-3-Pass标签设置">
        <span class="has-mr-6">1.1.3</span>
        <span>0.3 Pass标签设置</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#1-编译指令">
        <span class="has-mr-6">1.2</span>
        <span>1 编译指令</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#1-1-顶点着色器函数">
        <span class="has-mr-6">1.2.1</span>
        <span>1.1 顶点着色器函数</span>
        </a></li><li>
        <a class="is-flex" href="#1-2-片元着色器函数">
        <span class="has-mr-6">1.2.2</span>
        <span>1.2 片元着色器函数</span>
        </a></li><li>
        <a class="is-flex" href="#1-3-数据结构">
        <span class="has-mr-6">1.2.3</span>
        <span>1.3 数据结构</span>
        </a></li><li>
        <a class="is-flex" href="#1-4-语义">
        <span class="has-mr-6">1.2.4</span>
        <span>1.4 语义</span>
        </a></li><li>
        <a class="is-flex" href="#1-5-顶点着色器和片元着色器通信">
        <span class="has-mr-6">1.2.5</span>
        <span>1.5 顶点着色器和片元着色器通信</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#2-属性">
        <span class="has-mr-6">1.3</span>
        <span>2 属性</span>
        </a></li><li>
        <a class="is-flex" href="#3-内置文件">
        <span class="has-mr-6">1.4</span>
        <span>3 内置文件</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#3-1-UnityCG-cginc中一些常用的结构体">
        <span class="has-mr-6">1.4.1</span>
        <span>3.1 UnityCG.cginc中一些常用的结构体</span>
        </a></li><li>
        <a class="is-flex" href="#3-2-UnityCG-cginc中一些常用的帮助函数">
        <span class="has-mr-6">1.4.2</span>
        <span>3.2 UnityCG.cginc中一些常用的帮助函数</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#4-Shader-Model">
        <span class="has-mr-6">1.5</span>
        <span>4 Shader Model</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#4-1-Unity支持的Shader-Target">
        <span class="has-mr-6">1.5.1</span>
        <span>4.1 Unity支持的Shader Target</span>
        </a></li></ul></li></ul></li></ul>
        </div>
    </div>
</div>

    
    
</div>

            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container1">
        <div class="level1">
            <div class="level-start1 has-text-centered-mobile1">
                <a class="footer-logo is-block has-mb-6" href="/mystudy/">
                

                
                </a>
                <p class="is-size-7">
                &copy; 2020 Koliy&nbsp;
                Powered by <a href="https://github.com/koliy/koliy.github.io" target="_blank">Hexo</a> & <a
                        href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank">Icarus</a>
                
                <br>
                <span id="busuanzi_container_site_uv">
                共<span id="busuanzi_value_site_uv">0</span>个访客
                </span>
                
                </p>
            </div>
            <div class="level-end1">
            
            </div>
        </div>
    </div>
</footer>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("zh-CN");</script>

<script>
var IcarusThemeSettings = {
    article: {
        highlight: {
            clipboard: true,
            fold: 'unfolded'
        }
    }
};
</script>


    <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>



    
    
    
    <script src="/mystudy/js/animation.js"></script>
    

    
    
    
    <script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
    <script src="/mystudy/js/gallery.js" defer></script>
    

    
    

<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


    
    
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {
            matchFontHeight: false
        },
        SVG: {
            matchFontHeight: false
        },
        CommonHTML: {
            matchFontHeight: false
        },
        tex2jax: {
            inlineMath: [
                ['$','$'],
                ['\\(','\\)']
            ]
        }
    });
});
</script>

    
    

<a id="back-to-top" title="回到顶端" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/mystudy/js/back-to-top.js" defer></script>


    
    

    
    
    
    

    
    
    
    
    

    


<script src="/mystudy/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="想要查找什么..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(无标题)',
            },
            CONTENT_URL: '/mystudy/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/mystudy/js/insight.js" defer></script>
<link rel="stylesheet" href="/mystudy/css/search.css">
<link rel="stylesheet" href="/mystudy/css/insight.css"><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({"tex2jax":{"inlineMath":[["$","$"],["\\(","\\)"]],"skipTags":["script","noscript","style","textarea","pre","code"],"processEscapes":true},"TeX":{"equationNumbers":{"autoNumber":"AMS"}}});
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->
    
</body>
</html>